using System;
using System.Collections.Generic;
using System.Text;

namespace LogFileViewer
{
    public class LogFile
    {
        public LogFile(string filename)
        {
            this.filename = filename;
        }

        private string filename;

        /// <summary>
        ///     This is the full filename with path.
        /// </summary>
        public string Filename
        {
            get { return filename; }
            set { filename = value; }
        }

        private long fileLength;

        /// <summary>
        ///     The file length in bytes.
        /// </summary>
        public long FileLength
        {
            get { return fileLength; }
            set { fileLength = value; }
        }

        private MessageTypes messageTypeInLogFile;

        /// <summary>
        ///     The type of log messages populated in this file.
        ///     Mainly used for splitted file file handling.
        ///     When single file handling is activated,
        ///     this attribute will always be "UNDEFINED",
        ///     because every message type can be contained here.
        /// </summary>
        public MessageTypes MessageTypeInLogFile
        {
            get { return messageTypeInLogFile; }
            set { messageTypeInLogFile = value; }
        }

        private Dictionary<MessageTypes, int> logEntriesAmount;

        /// <summary>
        ///     Contains the amount of log messages (length of list)
        ///     for each MessageType in this file.
        /// </summary>
        public Dictionary<MessageTypes, int> LogEntriesAmount
        {
            get { return logEntriesAmount; }
            set { logEntriesAmount = value; }
        }

        /// <summary>
        ///     Sets the amount of log entries for a specified message type.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="amount"></param>
        public void setLogEntriesAmount(MessageTypes type, int amount)
        {
            if (this.logEntriesAmount == null)
            {
                this.logEntriesAmount = new Dictionary<MessageTypes, int>(MessageType.Length());
            }
            if (!this.logEntriesAmount.ContainsKey(type))
            {
                this.logEntriesAmount.Add(type, amount);
            }
            else
            {
                this.logEntriesAmount[type] = amount;
            }
        }

        private int logEntriesAmountAll = 0;

        /// <summary>
        ///     Returns the sum of all log entries in this file.
        /// </summary>
        public int LogEntriesAmountAll
        {
            get
            {
                if (logEntriesAmount != null)
                {
                    int sum = 0;
                    foreach (int listLength in this.logEntriesAmount.Values)
                    {
                        sum += listLength;
                    }
                    return sum;
                }
                return logEntriesAmountAll;
            }
            set
            {
                this.logEntriesAmountAll = value;
            }
        }
    }
}
